<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
 <button onclick="begin()">开始</button>
 <button onclick="resume()">resume</button>
</body>

</html>
<script>
    /*
        new speechBot({
            text:"测试",
            pitch:1,
            rate:1,
            volume:20,
            lang:'zh-CN'
        })
    */
    class speechBot {
        constructor(param) {
            this.speechProgress = window.speechSynthesis
            this.speechApi = new SpeechSynthesisUtterance()
            this.speechApi.text = param.text ?? "没传入文本"
            this.speechApi.rate = param.rate ?? 1
            this.speechApi.volume = param.volume ?? 1
            this.speechApi.lang = param.lang ?? "zh-CN"
            this.speechApi.pitch = param.pitch ?? 1.5
            this.speechProgress.onerror=(event)=>{
                console.log(`err:${event}`)
            }
        }
        speak = function (text) {
            // console.log(text,this.speechProgress)
            this.speechApi.text = text
            this.speechProgress.speak(this.speechApi)
        }
        pause = function () {
            this.speechProgress.pause()
        }
        resume = function () {
            // 暂停和非暂停切换
            this.speechProgress.resume()
        }
        cancel = function () {
            // 删除所有话语
            this.speechProgress.cancel()
        }
        configGet = function () {
            // console.log(this.speechProgress.getVoices())
        }
    }


    let ceshi = new speechBot({
            text: "测试",
            pitch: 1,
            rate: 1,
            volume: 20,
            lang: 'zh-CN'
        })
        // ceshi.speak("dddddd33")
    function begin(){
        ceshi.speak("ddddddddd33")
    }
    function resume(){
        ceshi.cancel()
    }
   

    class realizenBot {
        constructor(param) {
            this.speechProgress = window.speechSynthesis
            this.speechApi = new SpeechSynthesisUtterance()
            this.speechApi.text = param.text ?? "没传入文本"
            this.speechApi.rate = param.rate ?? 1
            this.speechApi.volume = param.volume ?? 1
            this.speechApi.lang = param.lang ?? "zh-CN"
            this.speechApi.pitch = param.pitch ?? 1.5
            this.speechProgress.onerror=(event)=>{
                console.log(`err:${event}`)
            }
        }
        speak = function (text) {
            // console.log(text,this.speechProgress)
            this.speechApi.text = text
            this.speechProgress.speak(this.speechApi)
        }
        pause = function () {
            this.speechProgress.pause()
        }
        resume = function () {
            // 暂停和非暂停切换
            this.speechProgress.resume()
        }
        cancel = function () {
            // 删除所有话语
            this.speechProgress.cancel()
        }
        configGet = function () {
            // console.log(this.speechProgress.getVoices())
        }
    }

    // ceshi.cancel()
    // setTimeout(()=>{
    //     ceshi.pause("你好aaaaaaaaaaaaaaaaaa")
    // },1000)
    


</script>